package com.rbs.controller;

import com.rbs.entity.Brand;
import com.rbs.service.BrandService;
import com.rbs.service.Impl.BrandServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/addBrandController")
public class AddBrandController extends HttpServlet {
    private BrandService brandService = new BrandServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收客户端请求参数
        String name = request.getParameter("name");
        Brand brand = new Brand();
        brand.setName(name);
        int i = brandService.addBrand(brand);
        if (i > 0){
//            response.sendRedirect(request.getContextPath()+"/SelectAllBrandController");
            response.sendRedirect(request.getContextPath()+"/SelectAllBrandAndPhoneNum");
        }else {
            response.sendRedirect(request.getContextPath()+"/SelectAllBrandAndPhoneNum");
        }
    }
}
